package zl.jfreechart;

import java.awt.Font;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

@SuppressWarnings("serial")
public class SecondJFreeChart extends ApplicationFrame{

	public SecondJFreeChart(String title){
		super(title);
		setContentPane(createDemoPanel());
	}
	
	public static void main(String[] args){
		SecondJFreeChart sjc = new SecondJFreeChart("CityInfoPort公司组织架构图");
		sjc.pack();
		RefineryUtilities.centerFrameOnScreen(sjc);
		sjc.setVisible(true);
	}
	
	public static PieDataset createDataset(){
		DefaultPieDataset defaultPieDataset = new DefaultPieDataset();
		defaultPieDataset.setValue("管理人员", 10.02D);
		defaultPieDataset.setValue("市场人员", 20.23D);
		defaultPieDataset.setValue("开发人员", 60.02D);
		defaultPieDataset.setValue("OEM人员", 10.02D);
		defaultPieDataset.setValue("其他人员", 5.11D);
		return defaultPieDataset;
	}
	
	public static JFreeChart createChart(PieDataset piedataset){
		JFreeChart jfreechart = ChartFactory.createPieChart("CityInfoPort",piedataset,true,true,false);
		PiePlot pieplot = (PiePlot)jfreechart.getPlot();
		pieplot.setLabelFont(new Font("SansSerif",Font.BOLD,12)); 
		pieplot.setNoDataMessage("No data available"); 
		pieplot.setCircular(true); 
		pieplot.setLabelGap(0.01D);//间距 
		return jfreechart;
	}
	
	public static JPanel createDemoPanel(){
		return new ChartPanel(createChart(createDataset()));
	}
}
